package com.itheima.array;

public class ArrayDemo3 {

    public static void main(String[] args) {

        //需求：完成斗地主游戏的做牌和洗牌
        game();
    }

    public static void game() {

        //动态初始化一个数组，存储54张牌
        String[] poker = new String[54];

        //创建一个数组，存储牌的花色
        String[] colors = {"♦","♣","♥","♠"};

        //创建一个数组，存储牌的点数
        String[] numbers = {"3","4","5","6","7","8","9","10","J","Q","K","A","2"};

        //先遍历点数，再遍历花色
        int index = 0;
        for (int i = 0; i < numbers.length; i++) {

            for (int j = 0; j < colors.length; j++) {

                //拼接点数和花色
                String card = colors[j] + numbers[i];

                //把拼接好的牌放入数组
                poker[index++] = card;     //或poker[i * 4 + j] = card;
            }
        }

        //添加大小王
        poker[index++] = "🃏";
        poker[index] = "👲";

        //打印牌
        System.out.println("新牌：");
        for (int i = 0; i < poker.length; i++) {
            System.out.print(poker[i] + " ");
        }
        System.out.println();

        //洗牌，把牌的顺序随机打乱
        for (int i = 0; i < poker.length; i++) {
            int temp = (int)(Math.random() * poker.length);
            String temp1 = poker[i];
            poker[i] = poker[temp];
            poker[temp] = temp1;
        }

        //打印牌
        System.out.println("洗牌后：");
        for (int i = 0; i < poker.length; i++) {
            System.out.print(poker[i] + " ");
        }
        System.out.println();

    }

}
